class_name Stats
extends Resource

signal stats_changed

@export var max_health := 1
@export var art: Texture

var health: int: set = set_health
var block: int: set = set_block


func set_health(v: int) -> void:
	health = clampi(v, 0, max_health)
	stats_changed.emit()


func set_block(v: int) -> void:
	block = clampi(v, 0, 999)
	stats_changed.emit()
	
func take_damage(damage: int) -> void:
	if damage < 0:
		return
	var initial_damage = damage
	damage = clampi(damage - block, 0, damage)
	block = clampi(block - initial_damage, 0, block)
	health -= damage
	
func heal(amout: int) -> void:
	health += amout
	
	
func create_instance() -> Resource:
	var instance: Stats = duplicate()
	instance.health = max_health
	instance.block = 0
	return instance
